using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using oms.Shared.Data;
using oms.Shared.Models;

namespace oms.Modules.System.Models;

/// <summary>
/// 用户实体
/// </summary>
[Comment("用户信息")]
[Index(nameof(Username), Name = "username", IsUnique = true)]
public class SysUserEntity : BaseEntity
{
    /// <summary>
    /// 登录用户名
    /// </summary>
    [Column(TypeName = "varchar(20)")]
    [Comment("登录用户名")]
    [Required]
    // 唯一索引（对应原表的UNIQUE KEY `username`）
    public string Username { get; set; } = string.Empty;

    /// <summary>
    /// 密码
    /// </summary>
    [Column("password", TypeName = "char(48)")]
    [Comment("密码")]
    [Required]
    public string Password { get; set; } = string.Empty;

    /// <summary>
    /// 姓名
    /// </summary>
    [Column("full_name", TypeName = "varchar(20)")]
    [Comment("姓名")]
    [Required]
    public string FullName { get; set; } = string.Empty;

    /// <summary>
    /// 头像
    /// </summary>
    [Column("avatar", TypeName = "varchar(200)")]
    [Comment("头像")]
    public string? Avatar { get; set; }

    /// <summary>
    /// 微信openid
    /// </summary>
    [Column("wechat_openid", TypeName = "varchar(255)")]
    [Comment("微信openid")]
    public string? WechatOpenid { get; set; }

    /// <summary>
    /// 状态（normal：正常，disable：禁用，lock：锁定）
    /// </summary>
    [Column("status", TypeName = "varchar(30)")]
    [Comment("状态（0：正常，1：禁用，2：锁定）")]
    [EnumConverter(typeof(GenericEnumConverter<UserStatusEnum>))]
    public UserStatusEnum Status { get; set; } = UserStatusEnum.Normal; // 默认正常
}